var mysql = require("mysql")
var pool = mysql.createPool({
    host: "127.0.0.1",
    port: 3306,
    user: "root",
    password: "123456",
    database: "yiqing",
    connectionLimit: 2
})

pool.async = {}

pool.async.query = (sql, params = []) => {
    return new Promise((resolve, reject) => {
        pool.query(sql, params, (error, result, fields) => {
            if (error) {
                reject({ error })
            } else {
                resolve({ result, fields, error })
            }
        })
    })
}

module.exports = pool
